package com.vstudy.zx.dao;

import com.vstudy.zx.dao.provider.ConversationDaoProvider;
import com.vstudy.zx.entity.Conversation;
import com.vstudy.zx.utils.page.ConversationPage;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ConversationDao {
    @SelectProvider(type = ConversationDaoProvider.class, method = "selectByPage")
    @Results({
            @Result(column = "stu_id", property = "student",
                    one = @One(select = "com.vstudy.zx.dao.StudentDao.selectById"))
    })
    List<Conversation> selectByPage(@Param("page") ConversationPage page);

    // 查询个数
    @SelectProvider(type = ConversationDaoProvider.class, method = "count")
    int count(@Param("te_id") Long te_id, @Param("status") Boolean status);

    @Update("update tb_conversation set con_status=1 where con_id in(${sql_in});")
    int signRead(@Param("sql_in") String sql_in);

    @Select("select * from tb_conversation where con_id=#{conId}")
    Conversation selectById(Long conId);

    // 删除单个会话，级联删除msg
    @Select("call sp_delete_convs")
    int removeConvs(String sql_in);

    @Update("update tb_conversation set stu_status=#{status} where con_id=#{conId}")
    void updateStuStatus(@Param("conId") Long conId, @Param("status") boolean status);

    //插叙会话
    @Select("select * from tb_conversation where stu_id=#{stuId} and te_id=#{teId}")
    Conversation selectByStuTe(@Param("stuId") Long stuId, @Param("teId") Long teId);

    // 插入会话，并返回id
    @Insert("insert into tb_conversation(te_id,stu_id,con_status) values(#{te_id},#{stu_id},#{con_status})")
    @Options(useGeneratedKeys = true, keyProperty = "con_id")
    void add(Conversation conversation);


}
